home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST_PAI.C < prev    next >
C/C++ Source or Header  |  1992-08-14  |  4KB  |  115 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Updated: JAM 08/14/92 -- modernized template syntax, remove macro hacks
  13.  
  14. #include <cool/String.h>
  15. #include <cool/Pair.h>
  16. #include <cool/Pair.C>
  17. #include <test.h>
  18.  
  19.  
  20. Boolean compare_double_String (const CoolPair<double,CoolString>& s1,
  21.                    const CoolPair<double,CoolString>& s2) {
  22.   if (s1.get_first() == s2.get_first() && s1.get_second() == s2.get_second())
  23.     return TRUE;
  24.   return FALSE;
  25. }
  26.  
  27.  
  28. void test_int_char () {
  29.   CoolPair<int,char> p0;
  30.   TEST("CoolPair<int,char> p0", 1, 1);
  31.   CoolPair<int,char> p1(1,'a');
  32.   TEST("CoolPair<int,char> p1(1,'a')", 1, 1);
  33.   CoolPair<int,char> p2(p1);
  34.   TEST("CoolPair<int,char> p2(p1)", 1, 1);
  35.   TEST("p1.get_first()", p1.get_first(), 1);
  36.   TEST("p2.get_second()", p2.get_second(), 'a');
  37.   p1.set_first(2);
  38.   TEST("p1.set_first(2)", p1.get_first(), 2);
  39.   p1.set_second('b');
  40.   TEST("p1.set_second('b')", p1.get_second(), 'b');
  41.   TEST("p2 = p1", (p2 = p1), p1);
  42.   TEST("p1 == p2", (p1 == p2), TRUE);
  43.   TEST("p1 != p2", (p1 != p2), FALSE);
  44. }
  45.  
  46.  
  47. Boolean compare_int_charP(const CoolPair<int,char*>& s1,const CoolPair<int,char*>& s2){
  48.   if (s1.get_first() == s2.get_first() &&
  49.       (strcmp (s1.get_second(), s2.get_second()) == 0))
  50.     return TRUE;
  51.   return FALSE;
  52. }
  53.  
  54.  
  55. void test_int_charP () {
  56.   CoolPair<int,char*> p0;
  57.   TEST("CoolPair<int,char*> p0", 1, 1);
  58.   CoolPair<int,char*> p1(1,"AAA");
  59.   TEST("CoolPair<int,char*> p1(1,\"AAA\")", 1, 1);
  60.   p1.set_compare(&compare_int_charP);
  61.   TEST ("p1.set_compare(&compare_int_charP)", 1,1);
  62.   CoolPair<int,char*> p2(p1);
  63.   TEST("CoolPair<int,char*> p2(p1)", 1, 1);
  64.   TEST("p1.get_first()", p1.get_first(), 1);
  65.   TEST("p1.get_second()", strcmp (p1.get_second(), "AAA"), 0);
  66.   TEST("p2.get_second()", strcmp (p2.get_second(), "AAA"), 0);
  67.   p1.set_first(2);
  68.   TEST("p1.set_first(2)", p1.get_first(), 2);
  69.   p1.set_second("BBB");
  70.   TEST("p1.set_second(\"BBB\")", strcmp (p1.get_second(), "BBB"), 0);
  71.   TEST("p2 = p1", (p2 = p1), p1);
  72.   TEST("p1 == p2", (p1 == p2), TRUE);
  73.   TEST("p1 != p2", (p1 != p2), FALSE);
  74. }
  75.  
  76.  
  77. void test_double_String () {
  78.   CoolPair<double,CoolString> p0;
  79.   TEST("CoolPair<double,CoolString> p0", 1, 1);
  80.   CoolPair<double,CoolString> p1(1.0,CoolString("AAA"));
  81.   TEST("CoolPair<double,CoolString> p1(1.0,CoolString(\"AAA\"))", 1, 1);
  82.   CoolPair<double,CoolString> p2(p1);
  83.   TEST("CoolPair<double,CoolString> p2(p1)", 1, 1);
  84.   TEST("p1.get_first()", p1.get_first(), 1);
  85.   TEST("p1.get_second()", p1.get_second(), CoolString("AAA"));
  86.   TEST("p2.get_second()", p2.get_second(), CoolString("AAA"));
  87.   p1.set_first(2.0);
  88.   TEST("p1.set_first(2.0)", p1.get_first(), 2.0);
  89.   p1.set_second(CoolString("BBB"));
  90.   TEST("p1.set_second(CoolString(\"BBB\"))", p1.get_second(), "BBB");
  91.   TEST("p2 = p1", (p2 = p1), p1);
  92.   TEST("p1 == p2", (p1 == p2), TRUE);
  93.   TEST("p1 != p2", (p1 != p2), FALSE);
  94. }
  95.  
  96. void test_leak () {
  97.   for (;;) {
  98.     test_int_char ();
  99.     test_int_charP ();
  100.     test_double_String ();
  101.   }
  102. }
  103.  
  104. int main (void) {
  105.   START("CoolPair");
  106.   test_int_char ();
  107.   test_int_charP ();
  108.   test_double_String ();
  109. #if LEAK
  110.   test_leak ();
  111. #endif
  112.   SUMMARY();
  113.   return 0;
  114. }  
  115.